﻿using FluentValidation;
using FluentValidation.Results;
using WarehouseManagementSystem.DAL;
using WarehouseManagementSystem.Entities;
using WarehouseManagementSystem.Views.Pages;
using Wpf.Ui;

namespace WarehouseManagementSystem.ViewModels.Pages;

public partial class LoginViewModel(INavigationService navigationService, MemberRepository memberRepository,IValidator<Member> validator)
{
    public Member Member { get; set; } = new(){Name = "Admin", Password = "123456"};

    [RelayCommand]
    private async Task LoginAsync()
    {
        /*CreateTableResult createTableResult = await sqliteService.Connection.CreateTableAsync<Member>();

        Member member = new Member
        {
            Id = 1,
            Name = "Admin",
            Password = "123456",
            Role = 1,
            InsertDate = DateTime.Now
        };

        await sqliteService.Connection.InsertAsync(member);*/

        ValidationResult validationResult = await validator.ValidateAsync(Member);
        if (validationResult.IsValid)
        {
            AppData.CurrentUser = await memberRepository.FindFirst(Member.Name);

            bool navigate = navigationService.Navigate(typeof(CargoPage));

            if (navigate)
            {

            }
        }

        //Member? findMember = (await memberRepository.GetAll()).Find(m => m.Name == "Admin" && m.Password == "123456");

    }
}